<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html">
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
</head>
<body erke-hide>
</body>
<script>
/**
 * @param {number[][]} grid
 * @return {number}
 */
var maxAreaOfIsland = function(grid) {
    var max = 0, n, m;
        n = grid.length;
        m = grid[0].length;
        for(var i=0; i<n; i++){
            for(var j=0; j<m; j++)
            {
                if(grid[i][j] == 1)   
                    max = Math.max(dfs(grid,i,j), max);
            };
        };
    console.log(max);
    return max;
};
function dfs(grid,x0,y0){
	var n=grid.length;
	var m=grid[0].length;
	var sum=1;
	grid[x0][y0]=0;
	var dir=[[0,1],[0,-1],[1,0],[-1,0]];
    for(var i=0; i<4; i++){
        var x = x0 + dir[i][0];
        var y = y0 + dir[i][1];
        if(x>=0&&x<n&&y>=0&&y<m&&grid[x][y]==1)
            sum+=dfs(grid, x, y);
    }
    return sum;
};
var res=new maxAreaOfIsland(
[[0,0,1,0,0,0,0,1,0,0,0,0,0],
 [0,0,0,0,0,0,0,1,1,1,0,0,0],
 [0,1,1,0,1,0,0,0,0,0,0,0,0],
 [0,1,0,0,1,1,0,0,1,0,1,0,0],
 [0,1,0,0,1,1,0,0,1,1,1,0,0],
 [0,0,0,0,0,0,0,0,0,0,1,0,0],
 [0,0,0,0,0,0,0,1,1,1,0,0,0],
 [0,0,0,0,0,0,0,1,1,0,0,0,0]]);
</script>
</html>